﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravellerLib {
  public class Route {
    private string _start, _end;
    public string Start { get { return _start; } }
    public string End { get { return _end; } }
    private Tuple<int, int, int> _color;
    public Tuple<int, int, int> Color {get {return _color;}}
    public Route(string line) {
      string[] parts = line.Split(' ');
      if (parts.Length != 4 && parts.Length != 6)
        throw new ArgumentException("Must contain 4 or 6 parts separated by spaces.", "line");

      if (parts[0] != "route")
        throw new ArgumentException("Not a route descriptor.", "line");

      Tuple<int, int> end;
      string color;
      _start = parts[1];
      if (parts.Length == 4) {
        _end = parts[2];
        color = parts[3];
      } else {
        int x, y;
        end = TravellerUtils.TravellerToCartesian(parts[4]);
        x = end.Item1; y = end.Item2;
        x += Convert.ToInt32(parts[2]) * 32;
        y += Convert.ToInt32(parts[3]) * 40;
        _end = TravellerUtils.CartesianToTraveller(x, y);
        color = parts[5];
      }

      switch (color) {
        case "lightgreen":
          _color = Tuple.Create(127, 255, 127); break;
        case "lightblue":
          _color = Tuple.Create(127, 255, 255); break;
        case "red":
          _color = Tuple.Create(255, 0, 0); break;
        case "green":
          _color = Tuple.Create(0, 255, 0); break;
        case "blue":
          _color = Tuple.Create(0, 0, 255); break;
      }
    }
  }
}
